<?php
/**
 * @package      OWNServices
 * @subpackage   site
 *
 * @author       Sanawin Tinsuwan
 * @copyright    Copyright (C) 20014 Sanawin Tinsuwan. All rights reserved.
 * @license      http://www.gnu.org/licenses/gpl.html GNU/GPL, see LICENSE.txt
 */

defined('_JEXEC') or die();

class OWNServicesViewReportmembers extends JViewLegacy
{
	protected $state;

	/**
     * Execute and display a template script.
     *
     * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
     *
     * @return  mixed   A string if successful, otherwise a Error object.
     *
     * @since   1.6
     */
    public function display($tpl = null)
    {
        $app    = JFactory::getApplication();

        // If the user is a guest, redirect to the login page.
        $user = JFactory::getUser();
      
		// Get the view data.
        $this->state	= $this->get('State');
        $this->params	= $this->state->params;
		$this->canDo	= JHelperContent::getActions('com_ownservices');

		// Login check
		 if ($user->get('guest') == 1)
        {
            // Redirect to login page.
            $app->redirect(JRoute::_('index.php?option=com_ownservices&view=login', false));
            return;
        }

		// Access check
		if (!$this->canDo->get('core.manage.reportmembers')) {
			return JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR'));
		}

        // Escape strings for HTML output
        $this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx'));

        // Check for errors.
        if (count($errors = $this->get('Errors'))) {
            JError::raiseError(500, implode("\n", $errors));
            return false;
        }

		// Prepare the document
        $this->prepareDocument();

        // Display the view
        parent::display($tpl);
    }

    /**
     * Prepares the document
     *
     * @return    void
     */
    protected function prepareDocument()
    {
        $app        = JFactory::getApplication();
        $menu       = $app->getMenu()->getActive();
        $pathway    = $app->getPathway();
        $title      = null;

        // Because the application sets a default page title, we need to get it from the menu item itself
        /*if ($menu)
        {
            $this->params->def('page_heading', $this->params->get('page_title', $menu->title));
        }
        else
        {*/
            $this->params->def('page_heading', JText::_('COM_OWNSERVICES_REPORT_TRANSFER_MONEY_MEMBER'));
        //}

        // Set the page title
        $title      = $this->params->get('page_title', '');

        if (empty($title)) {
            $title  = $app->getCfg('sitename');
        }
        elseif ($app->getCfg('sitename_pagetitles', 0) == 1) {
            $title  = JText::sprintf('JPAGETITLE', $app->getCfg('sitename'), $title);
        }
        elseif ($app->getCfg('sitename_pagetitles', 0) == 2) {
            $title  = JText::sprintf('JPAGETITLE', $title, $app->getCfg('sitename'));
        }

        $this->document->setTitle($title);

        if ($this->params->get('menu-meta_description'))
        {
            $this->document->setDescription($this->params->get('menu-meta_description'));
        }

        if ($this->params->get('menu-meta_keywords'))
        {
            $this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
        }

        if ($this->params->get('robots'))
        {
            $this->document->setMetadata('robots', $this->params->get('robots'));
        }
    }
}